package phone.qyg.com.qyg.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.app.application.QXApplication;
import com.app.base.tool.BaseActivity;
import com.app.config.AppHttpKey;
import com.app.config.ApplicationConfig;
import com.app.utils.JSONTool;
import com.app.utils.OptionImageUtils;
import com.app.view.ItemImageView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.text.MessageFormat;

import phone.qyg.com.qyg.R;
import phone.qyg.com.qyg.model.*;
import phone.qyg.com.qyg.utils.AppHttpRequest;

/**
 * 作者：lblbh on 2017/12/14 11:52
 * 邮箱：lanbuhan@163.com
 * 功能：我的活动详情
 */
@ContentView(R.layout.my_act_detail)
public class MyActivityDetailActivity extends BaseActivity {

    @ViewInject(R.id.back)
    TextView back;

    @ViewInject(R.id.title)
    TextView title;

    @ViewInject(R.id.act_time)
    TextView act_time;

    @ViewInject(R.id.regis_time)
    TextView regis_time;

    @ViewInject(R.id.act_map)
    TextView act_map;

    @ViewInject(R.id.regis_create_time)
    TextView regis_create_time;

    @ViewInject(R.id.regis_name)
    TextView regis_name;

    @ViewInject(R.id.regis_phone)
    TextView regis_phone;

    @ViewInject(R.id.regis_address)
    TextView regis_address;

    @ViewInject(R.id.regis_remark)
    TextView regis_remark;

    @ViewInject(R.id.regis_state)
    TextView regis_state;

    @ViewInject(R.id.regis_state_reason)
    TextView regis_state_reason;

    @ViewInject(R.id.electronic_ticket)
    TextView electronic_ticket;

    @ViewInject(R.id.item_img)
    ItemImageView item_img;

    @ViewInject(R.id.regis_state_layout)
    LinearLayout regis_state_layout;

    @ViewInject(R.id.electronic_layout)
    LinearLayout electronic_layout;

    MyActDetail model;

    int id;

    @Override
    public void initSucessView() {
        Object obj = getTransModels();

        if(obj instanceof phone.qyg.com.qyg.model.MyActivity){
            phone.qyg.com.qyg.model.MyActivity myAct = (phone.qyg.com.qyg.model.MyActivity) obj;
            id= myAct.id;
        }
    }

    @Override
    public void initData(Bundle savedInstanceStat){
        if(id == 0)return;
        mapKeys.put(AppHttpKey.ID,String.valueOf(id));
        AppHttpRequest.httpRequestDefalut(ApplicationConfig.SIGN_DETAIL,
                mapKeys,
                new AppHttpRequest.OnAppHttpListener() {
                    @Override
                    public void onAppHttpState(boolean isState, String result) {
                        if(isState && JSONTool.isStatus(result)){
                            model = JSONTool.jsonDefaluTranClazz(result,null,MyActDetail.class);
                            setData();
                        }
                    }
                });
    }

    private void setData(){
        if(null == model) return;
        title.setText(setAttributeText(model.title));
        regis_create_time.setText(MessageFormat.format(QXApplication.getContext().getResources().getString(R.string.regis_time_key_supply),
                        setAttributeText(model.signDate)));
        act_time.setText(MessageFormat.format(QXApplication.getContext().getResources().getString(R.string.act_time_key_supply),
                        setAttributeText(model.actTime)));
        regis_time.setText(MessageFormat.format(QXApplication.getContext().getResources().getString(R.string.act_regis_end_time_key_two),
                        setAttributeText(model.signTime)));
        act_map.setText(setAttributeText(model.actaddress));
        regis_name.setText(setAttributeText(model.user_name));
        regis_phone.setText(setAttributeText(model.phone));
        regis_address.setText(setAttributeText(model.address));
        regis_remark.setText(setAttributeText(model.remark));
        regis_state.setText(setAttributeText(model.statusName));
        String color = model.color;
        if(isRequestStr(color)){
            regis_state.setTextColor(Color.parseColor(color));
        }

        electronic_ticket.setText(setAttributeText(model.verification_code));
        int status = model.status;
        electronic_layout.setVisibility((status == 2)?View.VISIBLE:View.GONE);
        regis_state_reason.setVisibility((status == 3)?View.VISIBLE:View.GONE);

        setImgPath(model.fixImgUrl,item_img, OptionImageUtils.getRectRatioAct());
    }

    @Event(value = {R.id.back,R.id.regis_state_reason})
    private void viewOnClick(View v){
        switch (v.getId()){
            case R.id.back:
                this.finish();
                break;
            case R.id.regis_state_reason:

                break;
        }
    }

    @Override
    public void initViewHandler() {

    }
}
